import json
import os
from .client import Client
from ..utils import *
from .data import *


def send_str(data: str, kill: bool = False) -> str:
    if kill:
        adb_kill_package('com.example.stresstest')
        os.system('adb shell am start com.example.stresstest/.MainActivity')
    while True:
        client = Client()
        client.connect_server()
        recv = client.client_send(json.dumps(get_connect_data()))
        if recv == 'Success':
            break

    client = Client()
    client.connect_server()
    recv = client.client_send(data)
    return recv


def send_data(data: dict, kill: bool = False) -> str:
    return send_str(json.dumps(data),kill)


if __name__ == '__main__':
    send_str('hello')
